var storage=window.localStorage;	           
var userInfo=storage.getItem("userInfo");
var userStr=JSON.parse(userInfo);
var userId=userStr.userId;
var studentInfo = {};
var studentId = "";
getStuId();
function getStuId(){
	$.ajax({
	    url:'showPersonInfoAction.do',
	    type:'POST', 
	    data:{userId:userId},
	    dataType:'json',
	    success:function(args){
	    	studentInfo = args;
	    	studentId = studentInfo.studentId;	  
	    	console.log(studentInfo);
	    	showStuInfo();//显示学生信息
	    	$('#commitBtn').click(getVal);//提交
	    },
	    error:function(){
	        console.log('错误');
	    },
	    complete:function(){
	        console.log('结束');
	    }
	});
}
function showStuInfo(){
	if(studentInfo.realName){
		$('#realName').val(studentInfo.realName);
	}
	if(studentInfo.sex){
		$('#sex').val(studentInfo.sex);
	}
	if(studentInfo.birthday){
		$('#birthday').val(studentInfo.birthday);
	}
	if(studentInfo.incomedate){
		$('#incomedate').val(studentInfo.incomedate);
	}
	if(studentInfo.grade){
		$('#grade').val(studentInfo.grade);
	}
	if(studentInfo.classId){
		$('#classId').val(studentInfo.classId);
	}
	if(studentInfo.height){
		$('#height').val(studentInfo.height);
	}
	if(studentInfo.weight){
		$('#weight').val(studentInfo.weight);
	}
	if(studentInfo.email){
		$('#email').val(studentInfo.email);
	}
	if(studentInfo.telephone){
		$('#telephone').val(studentInfo.telephone);
	}
	if(studentInfo.region){
		$('#region').val(studentInfo.region);
	}
	if(studentInfo.addr){
		$('#addr').val(studentInfo.addr);
	}
	if(studentInfo.jsons){
		$('#jsons').val(studentInfo.jsons);
	}
}
var realName = '';
var sex = '';
var grade = '';
var classId = '';
var height = '';
var weight = '';
var email = '';
var telephone = '';
var region = '';
var addr = '';
var jsons = '';
var addr = '';
var birthday = '';
var incomedate = '';
function getVal(){	
	realName = $.trim($('#realName').val());
	sex =$('#sex').find("option:selected").text();//
	grade = $.trim($('#grade').val());//
	classId = $.trim($('#classId').val());//
	height = $.trim($('#height').val());
	weight = $.trim($('#weight').val());
	email = $.trim($('#email').val());
	telephone =$.trim( $('#telephone').val());
	region = $.trim($('#region').val());
	addr = $.trim($('#addr').val());
	jsons = $.trim($('#jsons').val());
	birthday = $.trim($('#birthday').val());
	incomedate = $.trim($('#incomedate').val());	
	if(realName ==""){		
		$('#dialog p').text('真实姓名必填!');
		$('#dialog').show();
		return;
	}else if(telephone == ""){
		$('#dialog p').text('联系电话必填!');
		$('#dialog').show();
		return;
	}else{	
		var info = {
				userId : userId,
				studentId: studentId,
		    	realName : realName,
		    	sex : sex,
		    	grade : grade,
		    	classId : classId,
		    	height : height,
		    	weight : weight,
		    	email : email,
		    	telephone : telephone,
		    	region : region,
		    	addr : addr,
		    	jsons : jsons, 
		    	birthday : birthday,
		    	incomedate : incomedate	    	
		    };
		var stuInfo = JSON.stringify(info);  
		commit(stuInfo);
	}
}
function commit(stuInfo){
	$.ajax({
	    url:'editStudentInfoAction.do',
	    type:'POST', 
	    data:{"stuInfo":stuInfo},
	    dataType:'json',
	    success:function(args){
	    	if(args.status == 'succ'){
	    		$('#dialog p').text('修改成功!');
				$('#dialog').show();
	    	}	    	
	    },
	    error:function(){
	        console.log('错误');
	    },
	    complete:function(){
	        console.log('结束');
	    }
	});
}